package com.godz.frontData.index3;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.godz.mapper.index3MindMapper;
import com.godz.pojo.index3Mind;
import org.springframework.web.bind.annotation.*;
import java.util.List;
//我的身边人的名言
@RestController
public class mindData {
    final
    index3MindMapper mindMapper;

    public mindData(index3MindMapper mindMapper) {
        this.mindMapper = mindMapper;
    }

    @GetMapping("/index3/get/mind")
    public List<index3Mind> getMind(){
        return mindMapper.queryAllMind();
    }
    //查询单个
    @GetMapping("/index3/get/mindOne/{intId}")
    public index3Mind getOneMind(@PathVariable("intId") Integer integer) {
        return mindMapper.selectOne(
                new QueryWrapper<index3Mind>().eq("id", integer)
        );
    }
    //增加一条
    @PostMapping("/index3/post/addMind")
    public String addMind(@RequestBody index3Mind mind) {
        mindMapper.insert(mind);
        return "insert OK";
    }
    //修改一条
    @PostMapping("/index/post/editMind")
    public String editMind(@RequestBody index3Mind mind) {
        QueryWrapper<index3Mind> wrapper = new QueryWrapper<>();
        wrapper.eq("id", mind.getId());

        index3Mind mind1 = new index3Mind();
        mind1.setMindName(mind.getMindName());
        mind1.setMindEname(mind.getMindEname());
        mind1.setMindCon(mind.getMindCon());
        mind1.setMindImg(mind.getMindImg());

        mindMapper.update(mind1, wrapper);
        return "Update OK";
    }
    //删除一条
    @GetMapping("/index3/get/deleteMind/{id}")
    public String deleteMind(@PathVariable("id") Integer integer) {
        mindMapper.deleteById(integer);
        return "Delete Ok";
    }
}
